#
# Copyright 2023 Unionman Technology Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(Mindspore.AI)

add_definitions(-DOHOS_PLATFORM)

set(CMAKE_CXX_STANDARD 17)

set(NATIVE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

include_directories(${NATIVE_ROOT_PATH}
                    ${NATIVE_ROOT_PATH}/include
                    ${NATIVE_ROOT_PATH}/third_party/opencv/include/opencv4)

add_library(mslite_napi SHARED
            src/mslite_napi.cpp
            src/utils/napi_error.cpp
            src/utils/napi_utils.cpp)

# opencv
## libopencv_core
add_library( libopencv_core STATIC IMPORTED)
set_target_properties(libopencv_core
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_core.a)
target_link_libraries(mslite_napi PUBLIC libopencv_core)

## libopencv_imgcodecs
add_library( libopencv_imgcodecs STATIC IMPORTED)
set_target_properties(libopencv_imgcodecs
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_imgcodecs.a)
target_link_libraries(mslite_napi PUBLIC libopencv_imgcodecs)

## libopencv_imgproc
add_library( libopencv_imgproc STATIC IMPORTED)
set_target_properties(libopencv_imgproc
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_imgproc.a)
target_link_libraries(mslite_napi PUBLIC libopencv_imgproc)

## libopencv_highgui
add_library( libopencv_highgui STATIC IMPORTED)
set_target_properties(libopencv_highgui
       PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_highgui.a)
target_link_libraries(mslite_napi PUBLIC libopencv_highgui)

## libopencv_objdetect
add_library( libopencv_objdetect STATIC IMPORTED)
set_target_properties(libopencv_objdetect
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_objdetect.a)
target_link_libraries(mslite_napi PUBLIC libopencv_objdetect)

## libopencv_calib3d
add_library( libopencv_calib3d STATIC IMPORTED)
set_target_properties(libopencv_calib3d
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_calib3d.a)
target_link_libraries(mslite_napi PUBLIC libopencv_calib3d)

## libopencv_flann
add_library( libopencv_flann STATIC IMPORTED)
set_target_properties(libopencv_flann
       PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_flann.a)
target_link_libraries(mslite_napi PUBLIC libopencv_flann)

## libopencv_features2d
add_library( libopencv_features2d STATIC IMPORTED)
set_target_properties(libopencv_features2d
       PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_features2d.a)
target_link_libraries(mslite_napi PUBLIC libopencv_features2d)

## libopencv_dnn
add_library( libopencv_dnn STATIC IMPORTED)
set_target_properties(libopencv_dnn
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_dnn.a)
target_link_libraries(mslite_napi PUBLIC libopencv_dnn)

## libopencv_videoio
add_library( libopencv_videoio STATIC IMPORTED)
set_target_properties(libopencv_videoio
        PROPERTIES IMPORTED_LOCATION ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/libopencv_videoio.a)
target_link_libraries(mslite_napi PUBLIC libopencv_videoio)

## libade
add_library( libade STATIC IMPORTED )
set_target_properties(libade
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/libade.a)
target_link_libraries(mslite_napi PUBLIC libade)

## libittnotify
add_library( libittnotify STATIC IMPORTED )
set_target_properties(libittnotify
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/libittnotify.a)
target_link_libraries(mslite_napi PUBLIC libittnotify)

## liblibjpeg-turbo
add_library( liblibjpeg-turbo STATIC IMPORTED )
set_target_properties(liblibjpeg-turbo
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibjpeg-turbo.a)
target_link_libraries(mslite_napi PUBLIC liblibjpeg-turbo)

## liblibopenjp2
add_library( liblibopenjp2 STATIC IMPORTED )
set_target_properties(liblibopenjp2
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibopenjp2.a)
target_link_libraries(mslite_napi PUBLIC liblibopenjp2)

## liblibpng
add_library( liblibpng STATIC IMPORTED )
set_target_properties(liblibpng
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibpng.a)
target_link_libraries(mslite_napi PUBLIC liblibpng)

## liblibprotobuf
add_library( liblibprotobuf STATIC IMPORTED )
set_target_properties(liblibprotobuf
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibprotobuf.a)
target_link_libraries(mslite_napi PUBLIC liblibprotobuf)

## liblibtiff
add_library( liblibtiff STATIC IMPORTED )
set_target_properties(liblibtiff
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibtiff.a)
target_link_libraries(mslite_napi PUBLIC liblibtiff)

## liblibwebp
add_library( liblibwebp STATIC IMPORTED )
set_target_properties(liblibwebp
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/liblibwebp.a)
target_link_libraries(mslite_napi PUBLIC liblibwebp)

## libquirc
add_library( libquirc STATIC IMPORTED )
set_target_properties(libquirc
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/libquirc.a)
target_link_libraries(mslite_napi PUBLIC libquirc)

## libtegra_hal
add_library( libtegra_hal STATIC IMPORTED )
set_target_properties(libtegra_hal
        PROPERTIES IMPORTED_LOCATION
        ${NATIVE_ROOT_PATH}/third_party/opencv/${OHOS_ARCH}/opencv4/3rdparty/libtegra_hal.a)
target_link_libraries(mslite_napi PUBLIC libtegra_hal)

target_link_libraries(mslite_napi PUBLIC hilog_ndk.z)
target_link_libraries(mslite_napi PUBLIC ace_ndk.z)
target_link_libraries(mslite_napi PUBLIC ace_napi.z)
target_link_libraries(mslite_napi PUBLIC libc++.a)
target_link_libraries(mslite_napi PUBLIC z)
target_link_libraries(mslite_napi PUBLIC uv)
target_link_libraries(mslite_napi PUBLIC mindspore_lite_ndk)
target_link_libraries(mslite_napi PUBLIC rawfile.z)